/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.mocking;

import picounit.mocker.Action;
import picounit.mocker.ListConsequenceCapturer;
import picounit.mocker.ListConsequenceMatcher;
import picounit.mocker.OccurencesMatcher;

import java.util.List;

@SuppressWarnings("unchecked")
class CombinedListConsequenceMatcher extends BaseConsequenceMatcher
	implements ListConsequenceMatcher, ListConsequenceCapturer {

	public CombinedListConsequenceMatcher(ActiveRecordingPlaybackMock activeRecordingPlaybackMock,
		OccurencesMatcher occurencesMatcher, MockInvocationInspector mockInvocationInspector) {

		super(activeRecordingPlaybackMock, occurencesMatcher, mockInvocationInspector);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// ListConsequenceMatcher methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public OccurencesMatcher andReturn(List result) {
		return will(returnValue(result));
	}

	@SuppressWarnings("unchecked")
	public OccurencesMatcher andReturn(Object ... results) {
		List<Object> list = createType(List.class);

		for (Object result : results) {
			list.add(result);
		}

		return will(returnValue(list));
	}

	public OccurencesMatcher andPerform(Action action) {
		return will(new ActionStub(action));
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// ListConsequenceCapturer methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	public OccurencesMatcher andReturning(List result) {
		return andReturn(result);
	}

	public OccurencesMatcher andReturning(Object... results) {
		return andReturn(results);
	}

	public OccurencesMatcher andPerforming(Action action) {
		return andPerform(action);
	}

	public void andRaising(Throwable throwable) {
		andRaise(throwable);
	}
}
